package com.gxa.ssm340.controller;

import com.gxa.ssm340.common.R;
import com.gxa.ssm340.entity.pojo.Menu;
import com.gxa.ssm340.service.RoleService;
import com.gxa.ssm340.uitl.JwtUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @author 赵文川
 * @Description: $
 * @date 2023/10/26 10:08
 */
@RestController
@RequestMapping("/role")
public class RoleController {
    @Autowired
    private RoleService roleService;

    @GetMapping("/getRole")
    public R getRole(HttpServletRequest request) {
        String token = request.getHeader("auth");
        String phone = JwtUtil.getPhone(token, "phone");
        String role = roleService.getRole(phone);
        return R.success(role);
    }

    @GetMapping("/getMenus")
    public R getMenus(HttpServletRequest request){
        String token = request.getHeader("auth");
        String phone = JwtUtil.getPhone(token, "phone");
        List<Menu> menus = roleService.getMenus(phone);
        return R.success(menus);
    }

}
